package src.percolation;

import java.util.Map;
import java.util.Random;
import java.util.TreeMap;

import org.apache.commons.math.stat.StatUtils;
import org.apache.commons.math.stat.regression.SimpleRegression;

import src.utils.Utils;

public class Pr1_d {
	
	public static void main(String[] argvs) throws Exception {
		
		
		
		int netSize;

		double minProba;
		double maxProba;
		double eps;
		

		try {
			netSize = new Integer(argvs[0]);
			minProba = new Double(argvs[1]);
			maxProba = new Double(argvs[2]);
			eps = new Double(argvs[3]);
			
		} catch (Exception e) {
			showUsage();
			return;
		}
		
		
		
		double probability;
		Random gen = new Random();
		
		for(probability = minProba;probability<maxProba;probability += eps) {
		
			long seed = gen.nextLong();
			Red myRed = new Red(netSize,seed);
			myRed.createGrid(probability);
			Map<Integer,Integer> clusterHistogram = myRed.clusterHistogram();
			
			Utils.printToFile(clusterHistogram, "A"+probability*1000+".dat");
		}	
	}

	private static void showUsage() {
		System.out.println("Usage: ");
		
		System.out.println("<netSize> <minProba> <maxProba> <increment> <eps> <meanOutFile> <sigmaOutFile>\n");
		
		System.out.println("<netSize>: size of net.");
		System.out.println("<minProba>: minimum probability.");
		System.out.println("<maxProba>: maximum probability.");
		System.out.println("<increment>: increment between probabilities.");
		
	}
}
